﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BASE;

public partial class Admin_xemdiem : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //check quyen vao trang

        if (Utils.getIntSession("userid") == 0)
        {
            Response.Redirect("/admin/login.aspx");
        }
        busMenu busM = new busMenu();
        if (!busM.checkQuyenVaoTrang(Utils.getIntSession("userid"), Constants.ADMIN_XEMDIEMTHEOMSV))
        {
            Response.Redirect("/admin/");
        }
        //set session forcus trang
        Session["trang"] = Constants.ADMINXEMDIEM;

        //lay diem sinh vien, ma sinh vien lay tren url
        if (!IsPostBack)
        {
            if (Utils.getStringQuery("masv") != "")
            {
                
                //check url
                if (Utils.getStringQuery("masv").Length > 15)
                {
                    MessenBox(1, "Mã sinh viên không đúng");
                    return;
                }
                //lay diem tbtl
                busDiem busD = new busDiem();
                List<entDiem> lst = new List<entDiem>();
                lst = busD.getDiemTBTL(Utils.getStringQuery("masv"));
                if (lst.Count > 0)
                {
                    lb_dtbtl.Text = lst[0].Diem.ToString();
                }

                
                getDiem(Utils.getStringQuery("masv"));
                txt_msv.Text=Utils.getStringQuery("masv");
            }
        }
        
    }
    protected void btn_xem_Click(object sender, EventArgs e)
    {
        //lay diem tbtl
        busDiem busD = new busDiem();
        List<entDiem> lst = new List<entDiem>();
        lst = busD.getDiemTBTL(txt_msv.Text);
        if (lst.Count > 0)
        {
            lb_dtbtl.Text = lst[0].Diem.ToString();
        }
        //check txt
        if (txt_msv.Text == "")
        {
            MessenBox(1, "Bạn chưa nhập mã sinh viên");
            return;
        }
        if (txt_msv.Text.Length >15)
        {
            MessenBox(1, "Mã sinh viên không đúng");
            return;
        }
        getDiem(txt_msv.Text);
    }
    void getDiem(string masv)
    {
        List<entDiem> lst = new List<entDiem>();
        busDiem busDiem = new busDiem();
        lst = busDiem.getNamHocHocKy(masv);
        Diem_DiemControl C2;
        int count = 1;
        foreach (entDiem item in lst)
        {
            C2 = (Diem_DiemControl)LoadControl("~/diem/DiemControl.ascx");
            C2.masv = masv;
            C2.nam = item.NamHoc + ":" + item.HocKy;
            C2.count = count;
            pn_re.Controls.Add(C2);
            count += C2.max;
        }
    }
}